package com.arron.algorithm;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Classname Test1
 * @Date 2020/9/10 20:57
 * @Created by 刘
 *
 * 将两个有序的数组合并，并排序
 */
public class Test1 {

    public static void main(String[] args) {

        int n = 9;



        StringBuilder sb = new StringBuilder();

        while (n>=1){
            sb.append("9");
            n--;
        }







    }


    public String test(String str1,String str2){
        int crray = 0;
        int i = str1.length()-1;
        int j = str2.length()-1;
        StringBuilder sb = new StringBuilder();
        while (i>=0 || j>=0){
            int temp = (str1.charAt(i)-'0')+(str2.charAt(j)-'0')+crray;
            crray = temp/10;
            sb.append(temp%10);
        }

        return sb.toString();
    }





    /**
     * 将两个有序的数组合并
     */
    public static int[] arrayMerge (int[] array1, int n, int[] array2, int m) {

        int[] z = new int[m+n];
        int k = 0;
        for (int i = 0; i < n; i++,k++){
            z[i] = array1[i];
        }
        for (int i = 0,l=k; i < m; i++,l++) {
             z[l] = array2[i];
        }


//        insertSort(z);
        return z;
    }

    public static void merge(int A[], int m, int B[], int n) {


//        int[] ints = new int[m + n];
//
//        for (int i = 0; i < m; i++) {
//            ints[i] = A[i];
//        }
//
//        for (int i = 0; i < n; i++) {
//            ints[m + i] = B[i];
//        }
//        insertSort(ints);

        int index = 0;

        for (int i = m; i < m+n; i++) {
            A[i] = B[index];
            index++;
        }
//        insertSort(A);

        Arrays.sort(A);
        for (int i : A) {
            System.out.println(i);
        }


    }
    /**
     * 直接插入排序
     */
    public static void insertSort(int[] a){
        //用于记录移动的元素的值
        int temp = 0;
        int j = 0;
        //从1开始
        for (int i = 1; i < a.length; i++) {
            temp = a[i];
            for (j = i-1; j>=0; j--) {
                if (a[j]>temp){
                    //如果前一个元素比temp大，就将temp位置替换成前一个元素的值
                    a[j+1] = a[j];
                }else {
                    //如果前一个数比temp小则跳出循环
                    break;
                }
            }
            //跳出循环，说明a[j]元素<=temp,则另a[j+1]为temp
            a[j+1] = temp;
        }
    }




}
